dojo.provide("miaigo.model.sgf.values.LabelValueHandler");

dojo.require("miaigo.model.sgf.values.PointValueHandler");
dojo.require("miaigo.model.sgf.values.TextValueHandler");

dojo.declare(
    "miaigo.model.sgf.values.LabelValueHandler",
    [miaigo.model.sgf.values.ValueHandler],
    {
	// label is a composed (point: simpletext),
	// where "point" is the position to place the label,
	// and "simpletext" is the label text.

	_valueType: "Label",

	_pointValueHandler: null,
	_simpleTextValueHandler: null,

	constructor: function()
	{
	    this._simpleTextValueHandler = new miaigo.model.sgf.values.TextValueHandler({isSimple: true});
	    this._pointValueHandler = new miaigo.model.sgf.values.PointValueHandler();
	},

	// Return: {position: {x: 6, y: 9}, label: "simple text"}
	parseValue: function(/* Array */values)
	{
	    var value = values[0];

	    if (value)
	    {
		var parts = value.split(":");
		if (parts.length == 2 &&
		    parts[0].length == 2)
		{
		    var position = this._pointValueHandler.parseValue([parts[0]]);
		    var label = this._simpleTextValueHandler.parseValue([parts[1]]);

		    return {position: position, label: label};
		}
	    }
	}
    });